package com.springTest;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.MultiValueMap;

import java.util.Arrays;

/**
 * @Author: YLBG-YCY-1325
 * @Description:
 * @Date: 2017/8/4
 */
public class MagicConditional implements Condition {
    @Override
    public boolean matches(ConditionContext conditionContext,
            AnnotatedTypeMetadata annotatedTypeMetadata) {
        Environment environment = conditionContext.getEnvironment();
        environment.acceptsProfiles("dev");
        MultiValueMap<String, Object> attrs = annotatedTypeMetadata
                .getAllAnnotationAttributes(Magic.class.getName());
        if (attrs != null) {
            for (Object value : attrs.get("value")) {
                System.out.println(Arrays.asList((String[]) value));
            }
            return false;
        }
        return true;
    }
}
